﻿using System;
using System.Collections.ObjectModel;
using System.Net;
using System.Runtime.Serialization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace SydEnergiPrototype.Model
{
    public class Entries : ObservableCollection<IEntry>{}

    [DataContract(Name = "Entry")]
    public class Entry : IEntry
    {
        [DataMember]
        public string CabinetId { get; set; }
        [DataMember]
        public IAddress EntryAddress { get; set; }
        [DataMember]
        public SolidColorBrush Fiber { get; set; }
        [DataMember]
        public SolidColorBrush Tube { get; set; }
        [DataMember]
        public int Cassette {get; set; } 
        [DataMember]
        public int Position { get; set; }
        [DataMember]
        public string Teletube { get; set; }
        [DataMember]
        public string InnerTubeId { get; set; }
        [DataMember]
        public int InnerTube { get; set; }
        [DataMember]
        public string LsseMb { get; set; }
        [DataMember]
        public string Cable { get; set; }
        [DataMember]
        public int FiberNumber { get; set; }
        [DataMember]
        public History EntryHistory { get; set; }

        public Entry(string cabinetId, IAddress address, SolidColorBrush fiber, SolidColorBrush tube, History history)
        {
            if(cabinetId == null)
                throw new ArgumentNullException("cabinetId");
            CabinetId = cabinetId;

            if(address == null)
                throw new ArgumentNullException("address");
            EntryAddress = address;

            if(fiber == null)
                throw new ArgumentNullException("fiber");
            Fiber = fiber;
            
            if(tube == null)
                throw new ArgumentNullException("tube");
            Tube = tube;

            if(history == null)
                throw new ArgumentNullException("history");
            EntryHistory = history;
        }

        public Entry(History history, IAddress address)
        {
            Fiber = new SolidColorBrush(Colors.Blue);
            Tube = new SolidColorBrush(Colors.Blue);
            
            if(history == null)
                throw new ArgumentNullException("history");
            EntryHistory = history;

            if(address == null)
                throw new ArgumentNullException("address");
            EntryAddress = address;
        }

        public override string ToString()
        {
            return EntryAddress + " " + Fiber + " " + Tube;
        }

        public override bool Equals(object obj)
        {
            if (obj == null)
                return false;

            var e = obj as Entry;
            if ((object)e == null)
                return false;

            return (CabinetId == e.CabinetId) && (EntryAddress.Equals(e.EntryAddress));
        }
    }
}
